package com.bjpowernode.springboot.controller;

import com.bjpowernode.springboot.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class MyController {

    @RequestMapping(value = "/user/detail",produces = "text/plain;charset=utf-8")
    public String userDetail(Model model){
        User user=new User();
        user.setId(1001);
        user.setUsername("李四");
        user.setAge(22);
        model.addAttribute("user",user);
        return "userDetail";
    }

    @RequestMapping(value="/url")
    public String urlExpression(Model model){
        User user=new User();
        user.setId(1001);
        user.setUsername("李四");
        user.setAge(22);
        model.addAttribute("user",user);
        return "url";
    }

    @RequestMapping(value = "/test")
    public @ResponseBody String test(String username){
        return "请求路径/test，参数是："+username;
    }

    @RequestMapping(value = "/test02")
    public @ResponseBody String test02(Integer id,String username,Integer age){
        return "请求路径/test02，参数是："+id+","+username+","+age;
    }

    @RequestMapping(value = "/test03/{username}")
    public @ResponseBody String test03(@PathVariable("username")String username){
        return "请求路径/test03，参数是："+username;
    }

    @RequestMapping(value = "/test04/{id}/{username}/{age}")
    public @ResponseBody String test04(@PathVariable("id") Integer id,
                                       @PathVariable("username") String username,
                                       @PathVariable("age") Integer age){
        return "请求路径/test04，参数是："+id+","+username+","+age;
    }

    @RequestMapping(value="/url2")
    public String url2(){
        return "url2";
    }

    @RequestMapping(value = "/properties")
    public String properties(){
        return "properties";
    }
}
